package basic.test;

import java.util.*;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/31 9:38
 */
public class XM3 {


    static HashMap<String, Integer> sMap;
    static HashMap<Character, String> cMap;
    static String[] ps = {"ZWUXG", "OTSFI"};

    static {
        sMap = new HashMap<>();
        cMap = new HashMap<>();
        sMap.put("ZERO", 2);
        sMap.put("ONE", 3);
        sMap.put("TWO", 4);
        sMap.put("THREE", 5);
        sMap.put("FOUR", 6);
        sMap.put("FIVE", 7);
        sMap.put("SIX", 8);
        sMap.put("SEVEN", 8);
        sMap.put("EIGHT", 0);
        sMap.put("NINE", 1);
        cMap.put('Z', "ZERO");
        cMap.put('W', "TWO");
        cMap.put('U', "FOUR");
        cMap.put('X', "SIX");
        cMap.put('G', "EIGHT");
        cMap.put('O', "ONE");
        cMap.put('T', "THREE");
        cMap.put('S', "SEVEN");
        cMap.put('F', "FIVE");
        cMap.put('I', "NINE");
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int l = in.nextInt();
        for(int i = 0; i < l; i++){
            System.out.println(cal(in.nextLine()));
        }
    }

    private static String cal(String s) {
        List<Integer> list = new ArrayList<>();
        int[] temp = new int[128];
        for (int i = 0; i < s.length(); i++) {
            temp[s.charAt(i)]++;
        }
        for (String s1 : ps) {
            for (char c1 : s1.toCharArray()) {
                if (temp[c1] > 0) {
                    int n1 = temp[c1];
                    String s2 = cMap.get(c1);
                    for (int i = 0; i < n1; i++) {
                        list.add(sMap.get(s2));
                    }
                    for (char c2 : s2.toCharArray()) {
                        temp[c2] -= n1;
                    }
                }
            }
        }
        Collections.sort(list);
        String res = "";
        for (int n2 : list) {
            res += n2;
        }
        return res;
    }
}
